package com.mc.servlet;

import com.mc.bean.Jury;
import com.mc.bean.Teacher;
import com.mc.service.JuryService;
import com.mc.service.TeacherService;
import com.mc.service.impl.JuryServiceImpl;
import com.mc.service.impl.TeacherServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wangcf
 * @version 1.0
 * @Description
 * @date 2023/2/14 15:42
 */
@WebServlet("/teacheradd.action")
public class TeacherAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TeacherService teacherService=new TeacherServiceImpl();
        String name = req.getParameter("name");
        String tel=req.getParameter("tel");
        String pass=req.getParameter("password");
        int age = Integer.parseInt(req.getParameter("age"));
        String sex = req.getParameter("sex");
        Teacher teacher=new Teacher(name,tel,pass,age,sex);
        System.out.println(teacher);
        boolean flag=teacherService.add(teacher);
        System.out.println(flag);
        String type = req.getParameter("type");
        System.out.println(type);
        if (type.equals("1")) {
            resp.sendRedirect("teacherlist.action");
        } else if(type.equals("2")){
            resp.sendRedirect("userlogin.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
